/*
Project: 		The Impact of Short-Term Employment for Low-Income Youth: Experimental 	
				Evidence from the Philippines
Authors: 		Emily A. Beam and Stella Quimbo

***********************************
Path: 			code/02_analysis
File name: 		table_a13_a16.do 
***********************************

Purpose: 		Generates Appendix Tables A13 (respondent has some or a lot of work experience by task) and A16 (impact on individual job-search behaviors)

Inputs: 		spes_data.dta
Outputs: 		Table A13 = table_a13.tex
				Table A16 = table_a16.tex
					

Log: 			results/03_output/log_table_a13_a16.log		

Last updated: 	16 November 2021
*/





cap log close

log using "$output/log_table_a13_a16.log",replace 


estimates clear

use "$usedata_analysis/spes_data",clear 
	keep if endline == 1




*** Set up local variables 

local l_bb_female "Female"
local l_NT_edu "College"

local intlist "_bb_female _NT_edu"

local n: word count $cov1
	assert `n' == 18 

** Interaction terms 

foreach interact in  `intlist' {
	
	foreach mes in tr spes_2016{
gen `mes'X`interact' = `mes'*`interact'
label var `mes'X`interact' "SPES X `l`interact''"

	}

assert !missing(`interact')

gen `interact'xtreatment = `interact'*treatment
label var `interact'xtreatment "SPES X `l`interact''"


* Generate inteaction terms for each covariate 

ds $cov1 
foreach cov in `r(varlist)'{ 
gen `interact'X`cov' = `cov'*`interact'
} 

}




* Set locals 

#delimit cr

* Job search
local jtypes "jscv jsonline jspeso jsfair jswalkin jsfam_refer jsoff"
local depvar5 "jobsearch `jtypes'"
local labels5 " " Any search" "Submit CV" "Online" "PESO" "Job fair" "Walk-in" "Fam/friend referral" "Officials"  " 

* Work tasks
ds _high_tasks*
rename _high_tasks* _ht*
rename _ht_onlinesearch _ht_onl

ds _ht*
local depvar6 "`r(varlist)'"
local labels6 ""Using Word" "Encoding" "Using Excel" "Using Powerpoint" "Photocopying" "Scanning" "Sorting" "Answering phones" "Bookkeeping" "Performing online searches" "Using e-mail""



										
loc w = 1				

loc name5 "jobsearc"
loc name6 "worktasks"
forval j = 6/6{		
					





*foreach mes in tr spes_2016{
local r replace



** Uninteracted version ** 
	foreach var in `depvar`j'' {
	
	
foreach mes in  spes_2016{

		xi:  ivregress 2sls  `var' (`mes' = treatment ) $cov1  i.scel if treatment!=. ,  robust
		estimates store iv`mes'`var'
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'


}
	
	}
}

global cov2 "_bb_female _bb_age  _bb_workany _bb_workformal _bb_worki _bb_la _bb_edulvl _f_bb_female _f_bb_age  _f_bb_workany _f_bb_workformal _f_bb_worki _f_bb_la "	// 2 missing



forval j = 5/5{		
					




*foreach mes in tr spes_2016{
local r replace



** Uninteracted version ** 
	foreach var in `depvar`j'' {
	
	
foreach mes in  spes_2016{

		xi:  ivregress 2sls  `var' (`mes' = treatment ) $cov2  i.scel if treatment!=. ,  robust
		estimates store iv`mes'`var'
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'


}



foreach interact in `intlist'  {


		
foreach mes in  spes_2016{

	
	qui	xi:  ivregress 2sls  `var' (`mes' `mes'X`interact' = treatment `interact'xtreatment) $cov2 `interact'X* i.scel if treatment!=. & _f`interact' == 0,  robust
		
		estimates store iv`mes'`w'`interact'
		di in red "estimates stored as iv`mes'`w'`interact'"
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'
		
		test `mes' + `mes'X`interact' == 0 
		estadd scalar pvalint = `r(p)'
}	// nature of IV loop
		

	
	}		// interaction term
	
	local w = `w' + 1
}		// individual dependent variables within each set
		
			
			
}		// dependent variable sets (tables)	





********************************************
********************************************
** Job Search and Work Tasks 
** No Heterogeneity 

** Table numbers 


loc tnjsearch = 9 // job search
loc tnwtask = 10 // work tasks

*** Footnote text *_bb_expected_earn _bb_expectedtuition _bb_othereducationexp  



local fn`tnjsearch' = "\multicolumn{9}{p{1.2\textwidth}}{\footnotesize{Notes: All endline respondents included. All specifications include controls listed in Table \ref{tbal} along with stratification-cell fixed effects, excluding expected daily wages after graduation, expected tuition, and expected educational expenses.  Panels B and C add controls multiplied by the binary interaction term along with uninteracted stratification-cell fixed effects.\textit{*** p$<$0.01, ** p$<$0.05, * p$<$0.10} }}\\"

local fn`tnwtask' = "\multicolumn{7}{p{0.9\textwidth}}{\footnotesize{Notes: All endline respondents included. All specifications include controls listed in Table \ref{tbal} along with stratification-cell fixed effects.  \textit{*** p$<$0.01, ** p$<$0.05, * p$<$0.10} }}\\"

********************************************
********************************************
cd "$tables_analysis"

#delimit ;
include "$dofiles/PanelCombine.do";




#delimit ;

********** Appendix Table XX - Work tasks    *************;
// Manually format tables; 
{;
ds _ht*;
local depvar6 "`r(varlist)'";


	// Output Tables ;

	
	
foreach mes in  spes_2016{;

	esttab iv`mes'_ht_word 	iv`mes'_ht_ppt 		iv`mes'_ht_sort 		iv`mes'_ht_onl
			iv`mes'_ht_encode 	iv`mes'_ht_photocopy 	 
	using table`tnwtask'_iv_`mes'1.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( N  dmean, fmt(%9.0f  %9.3f ) 
	labels( "Observations" "Mean, control group" )
 )
	keep(`mes') label 

	varwidth(16) modelwidth(13) style(tex) 
	title(Respondent has some or a lot of experience, by work task\label{twtask}) 
	varlabels(_cons Constant) 
mlabels(	"Using Word" 	"Powerpoint" 	"Sorting" 		"Performing online searchers" 	"Encoding" 
				"Photocopying" ,
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lccc ccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule");
};
	
foreach mes in  spes_2016{;

	esttab 	iv`mes'_ht_phone iv`mes'_ht_email   	
			iv`mes'_ht_excel 	iv`mes'_ht_scan	iv`mes'_ht_bookkeeping 
	using table`tnwtask'_iv_`mes'2.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( N  dmean, fmt(%9.0f  %9.3f ) 
	labels( "Observations" "Mean, control group" )
 )
	keep(`mes')   label

	varwidth(16) modelwidth(13) style(tex) 
	title(Respondent has some or a lot of experience, by work task\label{twtask}) 
	varlabels(_cons Constant) 
mlabels(	"Answering phones" 	"Using e-mail" 	"Using Excel" 		"Scanning" 	 	"Bookkeeping" 		,
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lccc ccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule" "`fn`tnwtask''" "\end{tabular}");


#delimit ;

panelcombine, use(table`tnwtask'_iv_`mes'1.tex table`tnwtask'_iv_`mes'2.tex)
columncount(5)  paneltitles("A" "B") cleanup
save(table_a13.tex);

};


};




********** Appendix Table A16 - Job Search - PANEL   *************;
{;
	
	
	// Output Tables ;

	
foreach mes in spes_2016{;
	
	esttab iv`mes'jobsearch iv`mes'jscv iv`mes'jsonline iv`mes'jspeso 
			iv`mes'jsfair iv`mes'jswalkin iv`mes'jsfam_refer iv`mes'jsoff   	
	using table`tnjsearch'_iv_`mes'.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
		noobs keep(`mes') label  

	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on labor-market perceptions and aspirations\label{tasp}) 
	varlabels(_cons Constant) 
mlabels(" Any search" "Submit CV" "Online" "PESO" "Job fair" "Walk-in" "Fam/ friend referral" "Officials"  , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
			mgroups("All" "Conditional on searching", pattern(1 1 0 0 0 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span}))

	prehead( "\begin{tabular}{lcccccccc}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule"  );

};

};

	//* Panel B Female;

	
foreach mes in  spes_2016{;

	esttab iv`mes'1_bb_female 		iv`mes'2_bb_female		iv`mes'3_bb_female		iv`mes'4_bb_female  
		 iv`mes'5_bb_female 		iv`mes'6_bb_female		iv`mes'7_bb_female		iv`mes'8_bb_female 
	using table`tnjsearch'_iv_`mes'_bb_female.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( pvalint , fmt(%9.3f  )  
	labels(  "p-value, SPES + SPES X Female")) 
	keep(`mes' `mes'X_bb_female) label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
mlabels(" Any search" "Submit CV" "Online" "PESO" "Job fair" "Walk-in" "Fam/ friend referral" "Officials"  , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lcccccccc}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule"  );

};
	//* Panel C Education ;
	
foreach mes in  spes_2016{;

	esttab iv`mes'1_NT_edu		iv`mes'2_NT_edu 			iv`mes'3_NT_edu		iv`mes'4_NT_edu
			iv`mes'5_NT_edu		iv`mes'6_NT_edu 			iv`mes'7_NT_edu		iv`mes'8_NT_edu
	using table`tnjsearch'_iv_`mes'_NT_edu.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats(pvalint N dmean , fmt(%9.3f  %9.0f %9.3f )  
	labels( "p-value, SPES + SPES X College" "Observations" "Mean, control group" )) 
	keep(`mes' `mes'X_NT_edu) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
mlabels(" Any search" "Submit CV" "Online" "PESO" "Job fair" "Walk-in" "Fam/ friend referral" "Officials"  , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	mgroups("All" "Conditional on searching", pattern(1 1 0 0 0 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span}))

	collabels(none)
	prehead( "\begin{tabular}{lcccccccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule" "`fn`tnjsearch''" "\end{tabular}" );
};





#delimit ;


// Combine panels ;

include "$dofiles/PanelCombine.do";


// Table Asp  - IV - self report ;
panelcombine, use(table`tnjsearch'_iv_spes_2016.tex table`tnjsearch'_iv_spes_2016_bb_female.tex table`tnjsearch'_iv_spes_2016_NT_edu.tex)  
columncount(5)  paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") cleanup
save(table_a16.tex) ;

log close;

